capture log close
clear all
set maxvar 10000
set more off
pause on
# delimit;

/* 
Figure B1 
*/

local data "" ;
local output "" ;
	
use "prwora_crime_compliers_all.dta", clear ;
drop if label == "" ;
foreach var of varlist _all { ;
	rename `var' n_`var' ;
} ;
rename n_label label ;
gen id = _n ;

reshape long n_, i(id) j(sample) string ;

drop id ;
reshape wide n_, i(sample) j(label) string ;
rename n_all 	complier ;
rename n_mean mean ;
rename n_mip complier_mip; 
replace sample = "dig_missing"  	if sample == "dig_0000" ;
replace sample = "dig_missing2" 	if sample == "dig_0001" ;
replace sample = "dig_missing3" 	if sample == "dig_2480" ;
replace sample = "dig_neurocog" 	if sample == "dig_2940" ;
replace sample = "dig_schiz" 		if sample == "dig_2950" ;
replace sample = "dig_affective" 	if sample == "dig_2960" ;
replace sample = "dig_autism" 		if sample == "dig_2990" ;
replace sample = "dig_anxiety" 		if sample == "dig_3000" ;
replace sample = "dig_personality" 	if sample == "dig_3010" ;
replace sample = "dig_adhd" 		if sample == "dig_3140" ;
replace sample = "dig_retard" 		if sample == "dig_3170" ;
replace sample = "dig_retard2" 		if sample == "dig_3180" ;
replace sample = "dig_retardborder" if sample == "dig_3195" ;
replace sample = "dig_cerebpalsy" 	if sample == "dig_3430" ;
replace sample = "dig_blind" 		if sample == "dig_3690" ;
replace sample = "dig_deaf" 		if sample == "dig_3890" ;

replace complier = complier - 1 ;


gen		sort = 19 if sample == "demo_male" ;
replace sort = 18 if sample == "demo_female" ;

replace sort = 16 if sample == "demo_black" ;
replace sort = 15 if sample == "demo_white" ;

replace sort = 13 if sample == "demo_parlow" ;
replace sort = 12 if sample == "demo_parhigh" ;
replace sort = 11 if sample == "demo_singno" ;
replace sort = 10 if sample == "demo_twopar" ;

replace	sort = 8 if sample == "firstage_lt6" ;
replace sort = 7 if sample == "firstage_7to13" ;
replace sort = 6 if sample == "firstage_gt13" ;
				
replace	sort = 4 if sample == "demo_othment" ;
replace sort = 3 if sample == "demo_intel" ;
replace sort = 2 if sample == "demo_phys" ;

replace	sort = 0 if sample == "demo_crimehigh" ;
replace sort = -1 if sample == "demo_ueallhigh" ;
replace sort = -2 if sample == "demo_demhigh" ;
replace sort = -3 if sample == "demo_pophigh" ;


twoway 
	/* dummy figure to create "dummy" yaxis(1) */
	(scatter sort complier if sort != . , color(white) yaxis(1))

	/* Actual figure */
	(scatter sort complier if (sample == "demo_male" | sample == "demo_female") 
			& sort != . , msymbol(X) color(blue) yaxis(2))
	(scatter sort complier if (sample == "demo_black" | sample == "demo_white") 
			& sort != . , msymbol(T) color(red) yaxis(2))
	(scatter sort complier if (sample == "demo_parlow" | sample == "demo_parhigh" | sample == "demo_singno" | sample == "demo_twopar") 
			& sort != . , msymbol(O) color(orange) yaxis(2))
	(scatter sort complier if (sample == "firstage_lt6" | sample == "firstage_7to13" | sample == "firstage_gt13") 
			& sort != . , msymbol(D) color(green) yaxis(2))
	(scatter sort complier if (sample == "demo_phys" | sample == "demo_intel" | sample == "demo_othment") 
			& sort != . , msymbol(S) color(purple) yaxis(2))
	(scatter sort complier if (sample == "demo_crimehigh" | sample == "demo_ueallhigh" | sample == "demo_demhigh" | sample == "demo_pophigh") 
			& sort != . , msymbol(t) color(teal) yaxis(2))
	
	, 
	legend(off)
	title("Complier characteristics", size(medsmall))
	ylabel(none, axis(1))
	ylabel( 		
			19 "Male"  18 "Female"  
			16 "Black" 15 "White" 
			13 "Low par earn" 12 "High par earn" 11 "Single/no par" 10 "Two parents"
			8 "On SSI before 6" 7 "On SSI 7-13" 6 "On SSI after 13"
			4 "Other mental" 3 "Intellectual" 2 "Physical"
			0 "High crime" -1 "High unemployment" -2 "High Dem share" -3 "High pop density"
		   , 
		   angle(0) notick labsize(small) axis(1) ) 
	ylabel("", nogrid axis(2)) 
	ytitle("", axis(1)) 
	ytitle("", axis(2)) 
	xsc(r(-.7 .7))
	xlab(-.75 "0.25" -.5 "0.5" -.25 "0.75" 0 "1" .25 "1.25" .5 "1.5" .75 "1.75", axis(1)) 
	xtitle("Under- or over-representation in complier group", size(medsmall))
	graphregion(color(white))
	bgcolor(white)
	xlabel(,nogrid)
	xline(0,lcolor(gray))
	yscale(lstyle(none) axis(1))
	yscale(lstyle(none) axis(2))
	;
graph export "`output'/figB1_a.png", width(1000) height(750) replace ;

	
gen 	sort3 = 18 if sample == "dig_adhd" ;
replace sort3 = 17 if sample == "n_diag1_resp" ;
replace sort3 = 16 if sample == "dig_anxiety" ;
replace sort3 = 15 if sample == "dig_personality" ;

replace sort3 = 14 if sample == "n_diag1_neo" ;
replace sort3 = 13 if sample == "dig_affective" ;
replace sort3 = 12 if sample == "dig_neurocog" ;
replace sort3 = 11 if sample == "dig_autism" ;
replace sort3 = 10 if sample == "n_diag1_musc" ;

replace sort3 = 9 if sample == "n_diag1_intel" ;
replace sort3 = 8 if sample == "n_diag1_cong" ;
replace sort3 = 7 if sample == "dig_schiz" ;
replace sort3 = 6 if sample == "n_diag1_blood" ;

replace sort3 = 5 if sample == "n_diag1_inj" ;
replace sort3 = 4 if sample == "n_diag1_nerv" ;
replace sort3 = 3 if sample == "n_diag1_sense" ;
replace sort3 = 2 if sample == "dig_cerebpalsy" ;

twoway 
	/* dummy figure to create "dummy" yaxis(1) */
	(scatter sort3 complier if sort3 != . , color(white) yaxis(1))

	/* Actual figure */
	(scatter sort3 complier if 
			(sample != "n_diag1_resp" &
			 sample ! = "n_diag1_neo" & sample != "n_diag1_musc" & sample != "n_diag1_cong" & 
			 sample ! = "n_diag1_blood" & sample != "n_diag1_nerv" & sample != "n_diag1_sense" & sample != "dig_cerebpalsy" &
			 sample != "n_diag1_intel" & sample != "dig_retardborder") & 
			 sort3 != . , msymbol(d) color(orange) yaxis(2))
			  
	(scatter sort3 complier if 
			(sample == "n_diag1_resp" |
			 sample == "n_diag1_neo" | sample == "n_diag1_musc" | sample == "n_diag1_cong" | 
			 sample == "n_diag1_blood" | sample == "n_diag1_nerv" | sample == "n_diag1_sense" | sample == "dig_cerebpalsy") &
			 sort3 != . , msymbol(s) color(green) yaxis(2))
			 
	(scatter sort3 complier if 
			(sample == "n_diag1_intel" | sample == "dig_retardborder") &
			 sort3 != . , msymbol(o) color(blue) yaxis(2))
	
	, 
	legend(off)
	title("Complier characteristics", size(medsmall))
	ylabel(none, axis(1))
	ylabel( 18 "ADHD" 17 "Asthma/resp" 16 "Anxiety" 15 "Personality" 14 "Cancer" 13 "Bipolar/affective" 		
			12 "Neurocognitive" 11 "Autism" 10 "Musculoskeletal" 9 "Intellectual" 8 "Congenital" 7 "Schizophrenia" 6 "Blood" 5 "Injury" 
			4 "Nervous" 3 "Blind or deaf" 2 "Cerebral Palsy" 
		   , 
		   angle(0) notick labsize(small) axis(1) ) 
	ylabel("", nogrid axis(2)) 
	ytitle("", axis(1)) 
	ytitle("", axis(2)) 
	xsc(r(-1 2))
	xlab(-1 "0" 0 "1" 1 "2" 2 "3", axis(1)) 
	xtitle("Under- or over-representation in complier group", size(medsmall))
	graphregion(color(white))
	bgcolor(white)
	xlabel(,nogrid)
	xline(0,lcolor(gray))
	yscale(lstyle(none) axis(1))
	yscale(lstyle(none) axis(2))
	;
graph export "`output'/figB1_b.png", width(1000) height(750) replace ;

